package IO流.OutPutStream01;

import org.junit.jupiter.api.Test;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

public class OutPutStream01 {
    public static void main(String[] args) {

    }
    @Test
    public void out_put_stream(){
        String filePath = "src/main/java/IO流/OutPutStream01/hello.txt";
        FileOutputStream fileOutputStream = null;

        try {
            //new FileOutputStream(filePath, true) 已追加的方式写入
            fileOutputStream = new FileOutputStream(filePath, true);
            //写入单个字节
            //fileOutputStream.write('H');
            String str = "hello world 大叫好";
            //str.getBytes(),将一个字符串转为一个字节数组,写入内容会覆盖之前的内容
            fileOutputStream.write(str.getBytes());

            //write(byte b[], int off, int len),写入指定位置的字符到文件，写入会覆盖之前内容
            //fileOutputStream.write(str.getBytes(),2,6);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                assert fileOutputStream != null;
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
